/**
 * IServiceHandler.java $version 1.0 2010. 08. 12
 *
 * Copyright 2010 NHN Corp. All rights Reserved.
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package com.eltonkent.dashboard.service;

/**
 * Description:
 * 
 * Service Manager API is the core functionality of the application. It's a
 * interworking framework for the consumer applications.This is done by using
 * Service Handler object. The Service Handler is generic API for any type of
 * services. It may be network service, Database service etc
 * 
 * <p>
 * This class has responsibility to initialize the queue and thread pool before
 * returning the service handler instance. The service handler will get
 * initialized from the DataManager. Once the service handler is initialized,
 * the queue will maintain all the services. The thread pool will monitor the
 * queue for any new service request arrival. Here Multiple thread design is
 * used for processing requests concurrently resulting in better user
 * experience. The implementation class should take care of initialization of
 * the service handler and expose the shutdown service to the service caller.
 * The DataManager API will provide access to the service handler to add the new
 * service and remove the existing services
 * </p>
 * 
 * @see com.nhn.android.wingspoon.model.servicemanager.SessionThreadPool
 * 
 * @author Accenture India
 */
public interface IServiceManager {

	/**
	 * Tries to remove from the work queue all ServiceTask tasks that have been
	 * cancelled. This method can be useful as a storage reclamation operation,
	 * that has no other impact on functionality. Cancelled tasks are never
	 * executed, but may accumulate in work queues until worker threads can
	 * actively remove them. Invoking this method instead tries to remove them
	 * now. However, this method may fail to remove tasks in the presence of
	 * interference by other threads.
	 * 
	 * @see com.nhn.android.servicemanager.queue.ServiceQueueManager#removeAll()
	 */
	public void cancelAllTasks();

	/**
	 * Shutdown the all running service's , This following step are done here.
	 * Initiates an orderly shutdown in which previously submitted tasks are
	 * executed, but no new tasks will be accepted. Invocation has no additional
	 * effect if already shut down
	 * 
	 * <ul>
	 * <li>Stop the all thread's in the thread pool and clean the thread pool
	 * instance
	 * <li>Clear the all service from the queue and clean the queue manager
	 * instance
	 * <li>Clean the service handler instance
	 * </ul>
	 * 
	 */
	public void shutdown();

	/**
	 * Access point for add the different type of services into the service
	 * handler . Before sending the response to data manager ,check terminated
	 * flag , if terminated flag is enabled the response will not go back to the
	 * data manager
	 * 
	 * @param task
	 *            Submits a value-returning task for execution.
	 * 
	 * @see IServiceTask
	 * 
	 */
	public <T> void submit(IServiceTask<T> task);

}
